Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacto ack and read #8100

Merged
merged 1 commit into from
Mar 13, 2025
Merged

Refacto ack and read #8100

merged 1 commit into from
Mar 13, 2025

Conversation

freddidierRTE
Copy link
Contributor

Back : extract ack an read logic in a new service

  • In release notes :
    • In chapter : Features Bugs Tasks
    • Text : #xxx ...

@freddidierRTE freddidierRTE marked this pull request as draft March 12, 2025 17:03
Copy link

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

This pull request shifts the responsibility for handling card read and acknowledgment actions from the existing service to a newly introduced service, CardReadAndAckService. The changes involve adding a new private field and a public getter for CardReadAndAckService in the configuration class, along with updating the CardController to delegate operations—such as posting and deleting user acknowledgments and reads—to the new service. In parallel, several methods that previously managed these operations have been removed from the CardProcessingService. The modifications are also reflected in the tests: the test suite now initializes and employs the new service, and a dedicated test class has been added to validate its functionality, including ensuring that proper events are dispatched when card statuses are reset.

Suggested reviewers

  • HubertDuchatelle

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@freddidierRTE freddidierRTE marked this pull request as ready for review March 13, 2025 08:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
services/cards-publication/src/main/java/org/opfab/cards/publication/services/CardReadAndAckService.java (2)

26-28: Initialize fields as final for immutability.
If these service references are not intended to be re-assigned, consider declaring them as final to ensure immutability and improve clarity.

- private CardNotificationService cardNotificationService;
- private CardRepository cardRepository;
- private CardPermissionControlService cardPermissionControlService;
+ private final CardNotificationService cardNotificationService;
+ private final CardRepository cardRepository;
+ private final CardPermissionControlService cardPermissionControlService;

39-49: Refactor membership check logic to avoid duplication and improve clarity.
You implement a membership check here and again at lines 73–78. Consider extracting this logic into a dedicated helper method to keep the code DRY.

+ private void validateUserEntities(CurrentUserWithPerimeters user, List<String> entitiesAcks, String errorMsg) {
+    if (!user.getUserData().getEntities().containsAll(entitiesAcks)) {
+        throw new ApiErrorException(new ApiError(HttpStatus.FORBIDDEN, errorMsg));
+    }
+ }

public UserBasedOperationResult processUserAcknowledgement(String cardUid, CurrentUserWithPerimeters user,
        List<String> entitiesAcks) {
    if (cardPermissionControlService.isCurrentUserReadOnly(user) && entitiesAcks != null && !entitiesAcks.isEmpty()) {
        throw new ApiErrorException(
            new ApiError(HttpStatus.FORBIDDEN, "Acknowledgement impossible : User has READONLY opfab role"));
    }
-   if (!user.getUserData().getEntities().containsAll(entitiesAcks))
-       throw new ApiErrorException(
-               new ApiError(HttpStatus.FORBIDDEN,
-                   "Acknowledgement impossible : User is not member of all the entities given in the request"));

+   validateUserEntities(user, entitiesAcks,
+       "Acknowledgement impossible : User is not member of all the entities given in the request");

    cardRepository.findByUid(cardUid).ifPresent(selectedCard ->
        cardNotificationService.pushAckOfCardInEventBus(cardUid, selectedCard.id, entitiesAcks, CardOperationTypeEnum.ACK));
    ...
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4db679b and e19524f.

📒 Files selected for processing (6)
  • services/cards-publication/src/main/java/org/opfab/cards/publication/configuration/Services.java (5 hunks)
  • services/cards-publication/src/main/java/org/opfab/cards/publication/controllers/CardController.java (8 hunks)
  • services/cards-publication/src/main/java/org/opfab/cards/publication/services/CardProcessingService.java (0 hunks)
  • services/cards-publication/src/main/java/org/opfab/cards/publication/services/CardReadAndAckService.java (1 hunks)
  • services/cards-publication/src/test/java/org/opfab/cards/publication/services/CardProcessServiceShould.java (3 hunks)
  • services/cards-publication/src/test/java/org/opfab/cards/publication/services/CardReadAndAckServiceShould.java (1 hunks)
💤 Files with no reviewable changes (1)
  • services/cards-publication/src/main/java/org/opfab/cards/publication/services/CardProcessingService.java
🔇 Additional comments (24)
services/cards-publication/src/test/java/org/opfab/cards/publication/services/CardProcessServiceShould.java (4)

83-83: New CardReadAndAckService field added to test class

This field has been added as part of the refactoring to extract card read and acknowledgment functionality into a dedicated service.


114-114: Properly initializing the new CardReadAndAckService

The service is correctly initialized with the necessary dependencies (cardNotificationService and cardRepositoryMock).


892-894: Updated to use new CardReadAndAckService for user reads

The test now uses the dedicated CardReadAndAckService instead of the CardProcessingService for handling user reads, which aligns with the architectural refactoring.


897-898: Updated to use new CardReadAndAckService for user acknowledgements

The test correctly uses the new dedicated service for processing acknowledgements, maintaining the same test behavior while adapting to the new architecture.

services/cards-publication/src/main/java/org/opfab/cards/publication/configuration/Services.java (5)

22-22: Added import for the new CardReadAndAckService

The import is correctly added to make the new service class available.


42-43: Added CardReadAndAckService as a private field

This field declaration follows the same pattern as other services in this class, maintaining consistency.


71-72: Improved formatting of CardNotificationService initialization

The service initialization has been reformatted for better readability.


83-83: Initializing the new CardReadAndAckService

The service is properly initialized with its required dependencies.


99-101: Added getter method for CardReadAndAckService

This getter method follows the same pattern as other service getters in this class, maintaining consistency in the API.

services/cards-publication/src/test/java/org/opfab/cards/publication/services/CardReadAndAckServiceShould.java (4)

25-27: New test class with proper Spring annotations

The test class is correctly set up with Spring test annotations to ensure proper integration with the test context.


32-37: Well-defined service and dependency fields

The test properly defines fields for the service under test and its dependencies, following standard testing patterns.


39-48: Clear test setup with BeforeEach

The initialization method properly sets up the testing environment before each test by creating fresh instances of dependencies and clearing the repository and event spy.


50-56: Test verifies event bus notification on reset operation

This test ensures that when card acknowledgments and reads are reset, an appropriate UPDATE notification is sent to the event bus, which is important for the system's reactive behavior.

services/cards-publication/src/main/java/org/opfab/cards/publication/controllers/CardController.java (8)

22-22: Added import for the new CardReadAndAckService

The import statement is correctly added to make the new service available in the controller.


48-48: Added CardReadAndAckService as a private field

The new service field is properly added to the controller class.


59-59: Initializing CardReadAndAckService in the constructor

The service is correctly retrieved from the Services class in the constructor.


180-180: Updated to use CardReadAndAckService for user acknowledgements

The controller now delegates acknowledgement processing to the specialized service instead of the generic card processing service.


208-208: Updated to use CardReadAndAckService for card read operations

Properly redirects the card read API call to the dedicated service.


234-234: Updated to use CardReadAndAckService for acknowledgement deletion

The controller now uses the specialized service for managing acknowledgement deletion.


259-259: Updated to use CardReadAndAckService for read deletion

The controller correctly uses the dedicated service for handling read status deletion.


309-309: Updated to use CardReadAndAckService for resetting reads and acknowledgements

The reset operation is now properly delegated to the specialized service.

services/cards-publication/src/main/java/org/opfab/cards/publication/services/CardReadAndAckService.java (3)

50-56: Confirm that the code handles missing cards as intended.
If the card cannot be found by UID, no event is triggered, and the method still returns a result. Ensure this silent behavior is what you want or consider informing the caller that the card does not exist.


73-78: Duplicate membership check logic.
This block duplicates the logic in lines 39–49.


86-95: Resetting read and ack states is consistent with the new service approach.
This logic effectively notifies the event bus only if the card is found, aligning well with the new separation of concerns.

@ClementBouvierN ClementBouvierN merged commit 9cd3eb6 into develop Mar 13, 2025
8 of 9 checks passed
@ClementBouvierN ClementBouvierN deleted the FE-refactoAck branch March 13, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants